﻿@using Telerik.Web.Mvc
@using Telerik.Web.Mvc.UI
@using Presentation.Web.Admin
@model  IEnumerable<Domain.Dto.PicThumbSizeDto>
@{
    ViewBag.subtitle = "图片缩略图大小设置";
    ViewBag.title = "图片缩略图大小设置";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@{Html.Telerik().Grid(Model)
    .Name("PicThumbSizeGrid")
    .ToolBar(toolBar => toolBar.Template(
    @<text>
    @{
        if (Html.HasUiPermission(this.ViewContext, "addpicthumbsize"))
        { 
        <a href="/pic?mode=insert" class='t-button  t-grid-add'>添加缩略图大小</a>
        }
        if (Html.HasUiPermission(this.ViewContext, "muldeletepicthumbsize"))
        { 
        <a href='javascript:;' class='t-button' onclick='mulDelete()'>删除选择项</a>
        }
    }
    <a href="javascript:;" class="t-button" style="float: right;" onclick="history.go(-1)">
        返回</a>
    </text>))
    .Columns(columns =>
    {
        columns.Template(@<text><input name="selectRow" type="checkbox" value="@item.Id " title="checkedRecords" /></text>)
        .HeaderTemplate(@<text><input type="checkbox" title="选择所有" id="checkAllRecords" /></text>)
        .Width(50).HeaderHtmlAttributes(new { style = "text-align:center" }).HtmlAttributes(new { style = "text-align:center" })
        .ClientTemplate("<input type=\"checkbox\" title=\"check all records\" name = 'selectRow' value = '<#= Id #>'/>");

        columns.Bound(o => o.Id).Width(50).Title("系统Id").Hidden();
        columns.Bound(o => o.Name).Width(200).Title("名称");
        columns.Bound(o => o.Remark).Width(200).Title("描述");
        columns.Bound(o => o.ThumbWidth).Width(50).Title("缩略图宽");
        columns.Bound(o => o.ThumbHeight).Width(50).Title("缩略图高");

        columns.Bound(o => o.IpAddress).Width(100).Title("添加IP").ReadOnly();
        columns.Bound(o => o.AddTime).Format("{0:yyyy-MM-dd HH:mm:ss}").Width(150).Title("添加时间").ReadOnly();
        columns.Bound(o => o.SortNum).Width(100).Title("排序号").Hidden();
        columns.Bound(o => o.State).Width(100).Title("状态").Hidden();
        columns.Command(comm =>
        {
            if (Html.HasUiPermission(this.ViewContext, "editpicthumbsize"))
            {
                comm.Edit().ButtonType(GridButtonType.Text);
            }
            if (Html.HasUiPermission(this.ViewContext, "deletepicthumbsize"))
            {
                comm.Delete().ButtonType(GridButtonType.Text);
            }
        }).Width(300).Title("编辑/删除");
    })
    .ClientEvents(clientEvents => clientEvents.OnDataBinding("dataBinding").OnComplete("bindComplete"))
    .DataKeys(key => key.Add("Id"))//添加主键
    .DataBinding(dataBinding => dataBinding.Ajax().Select("ajaxpicthumbsizeindex", "pic")
        .Insert("addpicthumbsize", "pic")
        .Update("editpicthumbsize", "pic")
        .Delete("deletepicthumbsize", "pic"))
    .Editable(editing => editing.Mode(GridEditMode.InLine))
    .Pageable(page => page.PageSize(15))
    .Render();
}
<script type="text/javascript">
    function dataBinding(args) {
        args.data = $.extend(args.data, {});
    }

    function mulDelete() {
        var delStr = $(':checked');
        if (delStr.length < 1) {
            alert('亲，您没有选择任何记录.');
            return;
        }
        jQuery.post('/pic/muldeletepicthumbsize', delStr, function (res) {
            if (res.success) {
                setTimeout(function () {
                    $("#PicThumbSizeGrid").data("tGrid").rebind();
                    $("#checkAllRecords").attr("checked", false);
                }, 1000);
            } else {
                alert(res.message);
            }
        });
    }

    function bindComplete(e) {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        var success = e.response.success;
        if (success != null && success != undefined) {
            alert(e.response.message);
            window.location.reload();
        }
    }

    $(function () {
        $("input:checkbox[name='selectRow']").attr("checked", false);
        $('#checkAllRecords').click(function checkAll() { $("#PicThumbSizeGrid tbody input:checkbox[name='selectRow']").attr("checked", this.checked); });
    });
</script>
